import ScrollBarLayout from '@/components/ScrollBarLayout';
import Cls from 'classnames';
import { useContext, useEffect } from 'react';
import { IntentionControllerContext } from '../common/useOAContext';
import { Spin } from 'antd';
import { useDescriptions, Descriptions } from '@/components/Descriptions';
import { formatDecimal, renderFileFunc } from '../../Acommon';
import moment from 'moment';

export const DetailInfoCenterViewMainOA: React.FC = () => {
  /** 引入上下文 */
  const { styleFixCls, infoObj } = useContext(IntentionControllerContext);

  /** 初始化 */
  useEffect(() => {
    if (infoObj?.id) {
      setFieldsValue({
        intentName: infoObj?.intentName,
        intentCode: infoObj?.intentCode,
        expectTime: moment(infoObj?.expectTime),
        applyTime: moment(infoObj?.applyTime).format('YYYY-MM-DD'),
        expectSum: formatDecimal(infoObj?.expectSum),
        purchaseInfo: infoObj?.purchaseInfo,
        applyerName: infoObj?.applyerName,
        applyDepartmentName: infoObj?.applyDepartmentName,
        applyPositionName: infoObj?.applyPositionName,
        applyPhone: infoObj?.applyPhone,
        remark: infoObj?.remark,
        attachURL: infoObj?.attachURL,
      });
    }
  }, [infoObj]);

  /** 表格表单配置信息 */
  const [config, { setFieldsValue }] = useDescriptions({
    labelWidth: 200,
    schemas: [
      {
        label: '意向公开申请',
        field: 'Title',
        component: 'Title',
      },
      {
        label: '申请日期',
        field: 'applyTime',
        component: 'Input',
        placeholder: '自动带出',
        disabled: true,
        required: false,
      },
      {
        label: '流水单号',
        field: 'intentCode',
        component: 'Input',
        placeholder: '自动带出',
        disabled: true,
      },
      {
        label: '申请部门/单位',
        field: 'applyDepartmentName',
        component: 'Input',
        placeholder: '自动带出',
        disabled: true,
      },
      {
        label: '职务岗位',
        field: 'applyPositionName',
        component: 'Input',
        placeholder: '自动带出',
        disabled: true,
      },
      {
        label: '申请人',
        field: 'applyerName',
        component: 'Input',
        placeholder: '自动带出',
        disabled: true,
      },
      {
        label: '联系电话',
        field: 'applyPhone',
        component: 'Input',
        placeholder: '自动带出',
        disabled: true,
      },
      {
        label: '意向公开名称',
        field: 'intentName',
        component: 'Input',
        colSpan: 2,
        disabled: true,
      },
      {
        label: '预计采购时间',
        field: 'expectTime',
        placeholder: '请选择采购时间',
        component: 'DatePicker',
        required: true,
        allowClear: false,
        disabled: true,
      },
      // {
      //   label: '预算金额',
      //   field: 'expectSum',
      //   component: 'Input',
      //   disabled: true,
      //   contentAfter: '元',
      // },
      {
        label: '意向公开附件',
        field: 'attachURL',
        component: 'Render',
        placeholder: '--',
        slotRender: (text, record) => {
          return (
            <div style={{ marginLeft: 8 }}>
              {renderFileFunc({ record: record, fileName: 'attachURL', downloadAddress: '/purchaseSourceChangeController/downloadFile' })}
            </div>
          );
        },
      },
      {
        label: '采购需求概述',
        field: 'purchaseInfo',
        component: 'InputTextArea',
        colSpan: 2,
        maxLength: 200,
        showCount: true,
        required: true,
        autoSize: { minRows: 3, maxRows: 5 },
        disabled: true,
      },
      {
        label: '备注',
        field: 'remark',
        component: 'InputTextArea',
        placeholder: '请输入',
        colSpan: 2,
        maxLength: 200,
        showCount: true,
        // required: true,
        autoSize: { minRows: 3, maxRows: 5 },
        disabled: true,
      },
    ],
  });

  return (
    <>
      <div className="commonTabsBodyDom">
        <div className={Cls('tabsBodyInfoDom', `${styleFixCls}updateFormBox`)}>
          <ScrollBarLayout style={{ padding: '5px 100px' }}>
            <Spin spinning={false}>
              <Descriptions config={config} />
            </Spin>
          </ScrollBarLayout>
        </div>
      </div>
    </>
  );
};
